package com.mmo.cq.game.server.bean.server;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.wxd.batis.struct.DbColumn;
import org.wxd.batis.struct.DbTable;
import org.wxd.lang.bit.BitUtil;
import org.wxd.lang.save.ObjectSave;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: Troy.Chen(無心道, 15388152619)
 * @version: 2023-02-02 16:08
 **/
@Setter
@Getter
@Accessors(chain = true)
@DbTable(name = "server_seed")
public class Server_Seed extends ObjectSave {

    public enum Type {
        /** 账号 */
        User,
        /** 游戏角色 */
        Player,
        /** 公会 */
        Guild,
        /** 道具 */
        Goods,
        /** 邮件 */
        Mail,
        /** 杂项 */
        Other,
    }

    @DbColumn(key = true)
    private int sid;
    @DbColumn()
    private ConcurrentHashMap<Type, Long> seedGroupMap = new ConcurrentHashMap<>();

    /** 创建唯一id */
    public long newUid(Type type, int hexId) {
        Long merge = seedGroupMap.merge(type, 1L, Math::addExact);
        return BitUtil.merge64(hexId, merge);
    }

}
